package com.sky.mapper;

import com.sky.annotation.AutoFile;
import com.sky.dto.DishDTO;
import com.sky.entity.Dish;
import com.sky.entity.DishFlavor;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface DishMapper {

    /**
     * 根据分类id查询菜品数量
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

    /**
     * 分页查询
     * */
    @Select("select count(*) from dish")
    long count();

    List<DishVO> pageShow(Long categoryId, String name, Integer status, int start, int pageSize);




    /**
     *  新增菜品
     * */
    //插入菜品
    @AutoFile(value = OperationType.INSERT)
    void insertDish(Dish dish);
    // 插入口味
    void insertDishFlavor(List<DishFlavor> dishFlavorsList);

    /**
     * 特定id查询，返回该类
     * */
   @Select("select * from dish where id = #{id}")
    Dish getById(Long id);



    /**
     * 批量删除，和单个删除
     * */
    void deleteById(List<Long> ids);
     /**
      * 删除口味
      * */
    void deleteDishFlavor(List<Long> dishId);

    /**
     *  设置菜品状态
     * */
    @Update("update dish set status = #{status} where id = #{id}")
    void setStatus(Integer status, Long id);


    /**
     * category与dish查询
     * */
    DishVO getByPathId(Long id);
    /**
     *   dish与dishFlavor查询
     * */
    List<DishFlavor> selectDishFlavor(Long id);


    /**
     * 修改dish
     * */
    @AutoFile(value = OperationType.UPDATE)
    void updateDish(Dish dish);

    /**
     *  修改dishFlavor
     * */
    void updateDishFlavor(DishFlavor dishFlavor);

    /**
     *  查询categoryId然后分类
     * */
    List<Dish> getByCategoryId(Dish dish);
}
